//  withdrawaReview.js
const app = getApp()
const util = require("../../../utils/util.js")
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    search: {
      searchAddShow: false,
      BtnTxt: '添加',
      searchTip: '可输入用户ID、用户名称等',
      searchValue: '',
    },
    status: 'pending',
    statuschoose: 'pending',
    statusShow: false,
    list: [],
    pagenum: 1
    // 同意提现 = "approval";
    // 拒绝提现 = "cancel";
    // 等待提现 = "pending";
  },
  statuspop() {
    this.setData({ statusShow: true });
  },
  statusClose() {
    this.setData({ statusShow: false });
  },
  radioChange(event) {
    this.setData({
      statuschoose: event.detail
    });
    this.statusTap()
  },
  // 获取列表
  review: function () {
    var that = this;
    var data = {
      page: that.data.pagenum,
      value:that.data.search.searchValue,
      status: that.data.status,
      type: 'admin'
    };
    app.post('weixin/withdrawalRecord', data).then((res) => {
      if (res.code == 200) {
        var list = that.data.list;
        var dataArr = res.entity.content;
        list = list.concat(dataArr)
        that.setData({
          list: list,
          total: res.entity.totalElements
        })
      }
    }).catch((errMsg) => {
      console.log(errMsg);
      wx.showToast({
        title: "网络错误",
        icon: 'loading',
        duration: 2000
      })
    })
  },
  // 通过或否决
  reviewTap:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;
    var data = {
      id:id,
      type: status
    };
    app.post('weixin/approvalWithdrawal', data).then((res) => {
      console.log(res)
      if (res.code == 200) {
        var mess = status =='approval'?'已通过':'已否决';
        Toast.success(mess);
        that.setData({ list: [], pagenum: 1, })
        that.review();
      } else {
        console.log(res)
        wx.showToast({
          title:res.message,
          icon: 'loading',
          duration: 2000
        })
      }
    }).catch((errMsg) => {
      console.log(errMsg);
      wx.showToast({
        title: "网络错误",
        icon: 'loading',
        duration: 2000
      })
    })
  },
  searchChange: function (event) {
    this.setData({
      ['search.searchValue']: event.detail
    })
  },
  // 搜索
  onSearch: function () {
    this.setData({ list: [], pagenum: 1, })
    this.review();
  },
  statusTap: function () {
    var that = this;
    that.setData({
      statusShow: false,
      status: that.data.statuschoose,
      pagenum: 1,
      list: []
    });
    that.review();
  },
  statistics:function(){
    wx.navigateTo({
      url: '../../boss/withdrawalStatistics/withdrawalStatistics',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.review();
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      pagenum: 1
    })
    this.review();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var pagenum = that.data.pagenum + 1; //获取当前页数并+1
    that.setData({
      pagenum: pagenum, //更新当前页数
    })
    that.review();
  }
  
})